Package("com.green.web.ErpPackageAdd");
com.green.web.ErpPackageAdd = {	
		 addPrivilegeRule : function() {
			 if($("#privilegeRule").find("tr").length==10){
				 art.dialog.tips("新增套餐最多允许10条!");
				 return;
			 }
				var tr = "<tr>" +
						    "<td>" +
						       "优惠套餐名<input type=\"text\" name=\"name\" id=\"name\" class=\"input-text\" maxNumber=\"20\" value=\"\" reg='Required' tip=\"请输入套餐名\" tip-position=\"top\"/> " +
						       ",可享受 <input type=\"text\" name=\"discount\" id=\"discount\" reg='Float' maxNumber=\"10\" tip=\"请输入金额\"  tip-position=\"top\" class=\"input-text w_60\" style=\"width: 80px\" value=\"\" /> " +
						       "元购买, <select name=\"month\" id=\"month\" reg='Required' tip=\"请选择月份\"  tip-position=\"top\" style=\"margin-right:10px\">" +
						                    "<option value=\"\">选择月份</option>" +
											"<option value=\"1\">1个月</option>" +
											"<option value=\"2\">2个月</option>" +
											"<option value=\"3\">3个月</option>" +
											"<option value=\"4\">4个月</option>" +
											"<option value=\"5\">5个月</option>" +
											"<option value=\"6\">6个月</option>" +
											"<option value=\"7\">7个月</option>" +
											"<option value=\"8\">8个月</option>" +
											"<option value=\"9\">9个月</option>" +
											"<option value=\"10\">10个月</option>" +
											"<option value=\"11\">11个月</option>" +
											"<option value=\"12\">12个月</option>" +
										 "</select>" +
								"<a href=\"javascript:void(0);\" onclick=\"com.green.web.ErpPackageAdd.delAll(this,1);\" class=\"mini-button\"><span class=\"mini-button-text mini-button-icon icon-remove \">删除</span></a>" +										
							 "</td>" +									 
						 "</tr>";
				$("#privilegeRule").append(tr);
			},
		     delAll : function(obj,count) {
					var dotTable = $(obj).parent().parent().parent();
					if (dotTable.find("tr").length <= count) {
						art.dialog.tips("至少有一个套餐!");
						return;
					}
					art.dialog.confirm("是否确认删除!",function(){
					var tr=$(obj).parent().parent(); 
					$(tr).remove();
					});
					
			},toSubmit:function() {
				var detailTables = $("#privilegeRule");
				var dotJsonDetail = "[";  				
				for(var i=0;i<detailTables.find("tr").length;i++){
					var detailTable=detailTables.find("tr")[i];
					dotJsonDetail=dotJsonDetail+"{name:'"+$(detailTable).find("#name").val();
					dotJsonDetail=dotJsonDetail+"',discount:'"+$(detailTable).find("#discount").val();
					dotJsonDetail=dotJsonDetail+"',month:'"+$(detailTable).find("#month").val();
					dotJsonDetail=dotJsonDetail+"'},"
				}
				dotJsonDetail=dotJsonDetail.substring(0,dotJsonDetail.length-1);
				dotJsonDetail=dotJsonDetail+"]";
				
			var ErpPackage = {};
			ErpPackage.name = $("#name").val(), ErpPackage.type = $('input[name=type]:checked').val(),
					ErpPackage.limitCity = $("#limitCity").val(),
					ErpPackage.packagePrice = $("#packagePrice").val(),
					ErpPackage.positionId = $("#positionId").val(),
					ErpPackage.discountRatio = $("#discountRatio").val(),
					ErpPackage.freeDays = $("#freeDays").val(),
					ErpPackage.dotJsonDetail =dotJsonDetail
			if (validateForm($("#mainWraper"))) {
				$.ajax({
					url : ctx + '/erpPackage/save',
					dataType : 'json',
					type : 'post',
					data : ErpPackage,
					success : function(data) {
						if (data.message == "1") {
							art.dialog.optTips('保存成功', 2, "success");
							location.href = ctx + '/erpPackage/manager';
						}else if (data.message == "2"){
							art.dialog.optTips('岗位套餐类型已经存在', 2, "failure");
						}else {
							art.dialog.optTips('保存失败', 2, "failure");
						}
					}
				});
			}
		},getPosition:function() {
			var dataName = $("#positionName").val();
			art.dialog.data("dataName", dataName);
			art.dialog.data("returnFunName", "selectPosition");
			art.dialog.open(ctx + '/f7/index/getPosition', {
				title : '岗位选择',
				lock : true,
				skin : 'aero',
				padding : 0,
				width : 450,
				height : 500
			});
		},selectPosition: function (obj) {
			var orgList = "";
			var orgListName = "";
			for ( var i = 0; i < obj.length; i++) {
				if (orgList == "") {
					orgList = obj[i].id;
					orgListName = obj[i].name;
				} else {
					orgList = orgList + "," + obj[i].id;
					orgListName = orgListName + "," + obj[i].name;
				}
			}
			$('#positionName').val(orgListName);
			$('#positionId').val(orgListName);
		},onclickArea:function () {
			var areaName = "";
			var area = $(":checkbox:checked").each(function() {
				if (areaName != "") {
					areaName = areaName + "," + $(this).val();
				} else {
					areaName = $(this).val();
				}
			});
			$("#limitCity").val(areaName)
		},setCity :function () {
			$('#areadiv').hide();
			if (!$("#limitCity").val()) {
				change_error_style($("#limitCity"), "add")
			} else {
				change_error_style($("#limitCity"), "remove")
			}
		},onclickOrg:function (){
			art.dialog.data("returnFunName","selectOrg");
			art.dialog.open(ctx+'/f7/index/getErpOrg',{title: '城市选择', lock: true,  skin: 'aero',padding:0,width:450,height:365});
	  },getErpPositionType:function (){
		art.dialog.data("returnFunName","selectErpPositionType");
		var limitCity= $("#limitCity").val();
		if(null==limitCity||limitCity==""){
			art.dialog.alert("请选择城市");
			return;
		}
		art.dialog.open(ctx+'/f7/index/getPositionType?fkcuid='+limitCity,{title: '岗位选择', lock: true,  skin: 'aero',padding:0,width:450,height:365});
     }

}